<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/main1.css">
    <title>Document</title>
    <script type="text/javascript">
        window.onload = function(){
            var oBtn = document.getElementById('btn01');
            var oPop = document.getElementById('pop');
            var oCount = document.getElementById('count');
            var oShut = document.getElementById('shutoff');
            var timer = null;            

            oBtn.onclick = function(){

                //显示弹框
                oPop.style.display = 'block';

                //定义弹框显示的时间值
                var timeleft = 5;

                timer = setInterval(function(){                    
                    //时间值减1
                    timeleft--;

                    //改变显示的时间值
                    oCount.innerHTML = timeleft;

                    //当时间值为0时，隐藏弹框，将显示的时间值重置，并且关闭定时器
                    if(timeleft<1)
                    {
                       oPop.style.display = 'none';
                       oCount.innerHTML = 5;
                       clearInterval(timer);
                    }
                },1000)
            }

            oShut.onclick = function(){
                oPop.style.display = 'none';
                oCount.innerHTML = 5;
                clearInterval(timer);
            }
        }
    </script>
</head>
<body>
    <input type="button" value="弹出弹框" id="btn01">
    <div class="pop_main" id="pop">
        <div class="pop_con">
            <div class="pop_title">
                <h3>系统提示</h3>
                <a href="#" id="shutoff">×</a>
            </div>
            <div class="pop_detail">
                <p class="pop_text">亲！请关注近期的优惠活动！</p>
            </div>
            <div class="pop_footer">
                还有<span id="count">5</span>秒自动关闭弹框               
            </div>
        </div>
        <div class="mask"></div>
    </div>
</body>
</html>